package com.chutoutian.controller;

import com.chutoutian.common.Code;
import com.chutoutian.po.Category;
import com.chutoutian.service.CategoryService;
import com.chutoutian.vo.ResponseMessage;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(value = "/v1")
public class CategoryController {

    @Resource
    private CategoryService categoryService;

    @GetMapping(value = "/category/tree")
    public Object findTree() {
        return categoryService.findTree();
    }

    @GetMapping(value = "/category/{id}")
    public Object get(@PathVariable("id") String id) {
        return categoryService.get(id);
    }

    @PostMapping(value = "/category")
    public Object add(@RequestBody Category category) {
        categoryService.add(category);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @PutMapping("/category")
    public Object update(@RequestBody Category category) {
        categoryService.update(category);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }

    @DeleteMapping("/category/{id}")
    public Object delete(@PathVariable("id") String id) {
        categoryService.delete(id);
        return new ResponseMessage.Builder().code(Code.CODE_200).bulid();
    }


}
